<template>
    <div style="margin-bottom: 45px">

        <van-field label="项目编号:" name="projectID" :value="fromdata.projectID" label-width="4.5em" required readonly />
        <van-field label="项目名称:" name="projectName" :value="fromdata.projectName" label-width="4.5em" required
            readonly />
        <van-field label="地市:" name="city" :value="fromdata.city" label-width="2.5em" required readonly />
        <van-field label="县区:" name="counties" :value="fromdata.counties" label-width="2.5em" required readonly />
        <van-field readonly required :right-icon="chooseMeetingEditable ? 'arrow' : ''" name="publicCountyCodeValue"
                   :value="fromdata.publicCountyCodeValue" label="县域组织(公开市场):" label-width="10em"
                   @click="showCountyPicke()" :rules="[{ required: true, message: '请选择县域组织(公开市场)' }]"/>
        <van-popup v-model="showCountyPopup" position="bottom" get-container="body">
          <van-picker show-toolbar value-key="name" :columns="showCountyPickeColumns"
                      @confirm="showCountyPickeOnConfirm" @cancel="showCountyPopup = false" />
        </van-popup>
        <van-field label="客户编码:" name="customerId" :value="fromdata.customerId" label-width="4.5em" required readonly />
        <van-field label="客户名称:" name="customerUnitName" :value="fromdata.customerUnitName" label-width="4.5em" required
            readonly />
        <van-field label="项目竞争方式:" name="competitiveMode" :value="fromdata.competitiveMode" label-width="6.5em" required
            readonly />

        <van-field label="决策层级:" name="decisionLevel"
            :value="decisionMaking.decisionLevel ? decisionMaking.decisionLevel :'无' " label-width="4.5em" required
            readonly />
        <van-field v-if="!isSJ" label="地市会议纪要编号:" name="meetingNumber" :value="decisionMaking.meetingNumber"
            label-width="8.5em" required readonly />
        <van-field v-if="!isSJ" label="地市会议纪要名称:" name="meetingTheme" :value="decisionMaking.meetingTheme"
            label-width="8.5em" required readonly />
        <van-field v-if="isSJ" label="省公司会议纪要编号:" name="meetingNumberCompany"
            :value="decisionMaking.meetingNumberCompany" label-width="9.5em" required readonly />
        <van-field v-if="isSJ" label="省公司会议纪要名称:" name="meetingThemeCompany" :value="decisionMaking.meetingThemeCompany"
            label-width="9.5em" required readonly />

        <div v-if="chooseMeetingEditable"
            style="display: flex; justify-content: flex-end; align-items: center; height: 50px;">
            <el-button type="primary" size="small" icon="search" style="margin-right: 16px;"
                @click="chooseMeetingNumber">
                选择关联会议纪要
            </el-button>
        </div>

        <van-cell-group>
            <van-field label="客户合同是否约定交付时间:" name="isArrangePayTime" :value="fromdata.isArrangePayTime" readonly
                required label-width="13em" :right-icon="isArrangePayTimeEditable ? 'arrow' : ''"
                @click="isArrangePayTimeShowPopup = isArrangePayTimeEditable"
                :rules="[{ required: true, message: '请选择客户合同是否约定交付时间' }]" />
            <van-popup v-model="isArrangePayTimeShowPopup" position="bottom" get-container="body">
                <van-picker show-toolbar value-key="value" :columns="isArrangePayTimeColumns"
                    @cancel="isArrangePayTimeEditable = false" @confirm="isArrangePayTimeConfirm" />
            </van-popup>
        </van-cell-group>

        <van-field label="立项类型:" name="buildType" :value="mFromdata.buildType" label-width="4.5em" required readonly />
        <van-field label="项目实施类型:" name="projectServiceContent" :value="fromdata.projectServiceContent"
            label-width="6.5em" readonly />
        <van-field label="售中售后阶段项目预定级:" name="onProjectGrade" :value="fromdata.onProjectGrade" label-width="11.5em"
            readonly />
        <van-field v-if="showGradeFinal" required label="售中售后阶段项目定级:" name="onProjectGradeFinal"
            :value="fromdata.onProjectGradeFinal" label-width="10.5em" readonly >
          <template #button>
            <van-button size="small" native-type="button" type="primary" @click="getITList">评定</van-button>
          </template>
        </van-field>

        <van-field readonly required name="isUpDownAssociation" :value="fromdata.isUpDownAssociation"
            label="上下游是否存在关联关系:" label-width="12em" />
        <van-field readonly required name="isUpDownAB" :value="fromdata.isUpDownAB" label="上下游是否存在AB/BA关系:"
            label-width="13em" />
        <van-field readonly name="upDownProjectId" :value="fromdata.upDownProjectId ? fromdata.upDownProjectId :'无'"
            label="存在AB/BA关系项目编号:" label-width="12em" />
        <van-field readonly name="upDownProjectName"
            :value="fromdata.upDownProjectName ? fromdata.upDownProjectName :'无'" label="存在AB/BA关系项目名称:"
            label-width="12em" />
        <van-field readonly name="upDownCustomerName"
            :value="fromdata.upDownCustomerName ? fromdata.upDownCustomerName :'无'" label="存在AB/BA关系客户名称:"
            label-width="12em" />
        <van-field readonly name="upDownMdmName" :value="fromdata.upDownMdmName ? fromdata.upDownMdmName :'无'"
            label="存在AB/BA关系供应商名称:" label-width="13em" />
        <van-field readonly required name="associationPath" :value="fromdata.associationPath" label="关联路径:"
            label-width="5em" />
        <van-field readonly name="internalIncome" :value="fromdata.internalIncome" label="估算收益%:" label-width="6em" />


        <van-field readonly required name="autonomousImplemention" :value="fromdata.autonomousImplemention"
            label="是否自主实施:" label-width="7em" />
        <!-- 是否自主实施 “是” 有这一行 -->
        <van-field readonly required name="autonomousImplementionType"
            :value="fromdata.autonomousImplementionType" label="项目自主实施类型:" label-width="9em" />
        <van-field v-if="fromdata.autonomousImplemention == '是'" readonly required name="autImplementScope"
            :value="fromdata.autImplementScope" label="自主实施范围:" label-width="7em" />
        <van-field readonly name="entrustedSalesModel" :value="fromdata.entrustedSalesModel" label="是否受托代销项目:"
            label-width="9em" />


        <!-- 军团项目 -->
        <van-cell-group>
            <van-field readonly required name="isLegionProject"
                :value="fromdata.isLegionProject ? fromdata.isLegionProject : '否'" label="是否军团项目:" label-width="7em"
                :right-icon="isLegionProjectEditable ? 'arrow' : ''"
                @click="isLegionProjectShowPopupView = isLegionProjectEditable"
                :rules="[{ required: isLegionProjectEditable, message: '请选择是否是军团项目' }]" />
            <van-popup v-model="isLegionProjectShowPopupView" position="bottom" get-container="body">
                <van-picker show-toolbar :value-key="'value'" :columns="isArrangePayTimeColumns"
                    @confirm="isLegionProjectClickConfirm" @cancel="isLegionProjectShowPopupView = false" />
            </van-popup>
        </van-cell-group>
        <van-cell-group v-if="fromdata.isLegionProject === '是'">

            <van-field readonly name="industryLegion" :value="fromdata.industryLegion" label="行业军团:" label-width="5em"
                :right-icon="isLegionProjectEditable ? 'arrow' : ''" @click="industryLegionClick" />
            <van-popup v-model="industryLegionShowPopupView" position="bottom" get-container="body">
                <van-picker show-toolbar :value-key="'value'" :columns="industryLegionPopupColumns"
                    @confirm="industryLegionClickConfirm" @cancel="industryLegionShowPopupView = false" />
            </van-popup>

            <van-field readonly name="productLegion" :value="fromdata.productLegion" label="产品军团:" label-width="5em"
                :right-icon="isLegionProjectEditable ? 'arrow' : ''" @click="productLegionClick" />
            <van-popup v-model="productLegionShowPopupView" position="bottom" get-container="body">
                <van-picker show-toolbar :value-key="'value'" :columns="productLegionPopupColumns"
                    @confirm="productLegionClickConfirm" @cancel="productLegionShowPopupView = false" />
            </van-popup>
            <div class="redtext font11" style="margin: 5px 15px 0px 15px;">
                军团标签需至少选择其中之一，支持选择两类标签
            </div>

            <van-field readonly name="industryLegionUnits" :value="fromdata.industryLegionUnits" label="行业军团项目支撑单位:"
                label-width="11em" :right-icon="isLegionProjectEditable ? 'arrow' : ''"
                @click="industryLegionUnitsClick" />
            <van-popup v-model="industryLegionUnitsShowPopupView" position="bottom" get-container="body">
                <van-picker show-toolbar :value-key="'value'" :columns="industryLegionUnitsPopupColumns"
                    @confirm="industryLegionUnitsClickConfirm" @cancel="industryLegionUnitsShowPopupView = false" />
            </van-popup>

            <van-field readonly name="productLegionUnits" :value="fromdata.productLegionUnits" label="产品军团项目支撑单位:"
                label-width="11em" :right-icon="isLegionProjectEditable ? 'arrow' : ''"
                @click="productLegionUnitsClick" />
            <van-popup v-model="productLegionUnitsShowPopupView" position="bottom" get-container="body">
                <van-picker show-toolbar :value-key="'value'" :columns="productLegionUnitsPopupColumns"
                    @confirm="productLegionUnitsClickConfirm" @cancel="productLegionUnitsShowPopupView = false" />
            </van-popup>

            <van-field readonly name="isDifficultProject" :value="fromdata.isDifficultProject" label="是否重点难点项目:"
                label-width="9em" :right-icon="isLegionProjectEditable ? 'arrow' : ''"
                @click="isDifficultProjectShowPopupView = isLegionProjectEditable"
                :rules="[{ required: isLegionProjectEditable, message: '请选择是否重点难点项目' }]" />
            <van-popup v-model="isDifficultProjectShowPopupView" position="bottom" get-container="body">
                <van-picker show-toolbar :value-key="'value'" :columns="isArrangePayTimeColumns"
                    @confirm="isDifficultProjectClickConfirm" @cancel="isDifficultProjectShowPopupView = false" />
            </van-popup>
            <div v-if="fromdata.isDifficultProject === '是'"
                style="display: flex; justify-content: flex-end; align-items: center; height: 50px;">
                <el-button type="primary" size="small" icon="search" style="margin-right: 16px;"
                    @click="jtxm_lxr_showPopupView = true">
                    查看军团联系人
                </el-button>
            </div>
            <page-select-xm-list v-if="jtxm_lxr_showPopupView" v-on:update-flag="jtxm_lxr_showPopupView = false"
                v-on:select-item="handleSelectItem" pageTitle="军团联系人.列表" url="legionContracts$api$findAll"
                :withoutKV="{ 'direction': 'desc', 'properties': 'createdTime' }" :withoutBody="{ }">
                <template #body="{ item }">
                    <div>
                        <div class="titlefont"> 军团名称： {{ item.legionName }}</div>
                        <div class="infosfont"> 联系人： {{ item.contract }}</div>
                        <div class="infosfont"> 电话： {{ item.contractPhone }}</div>
                        <div class="infosfont"> 邮箱： {{ item.email }}</div>
                    </div>
                </template>
            </page-select-xm-list>



            <div class="redtext font11" style="margin: 5px 15px 0px 15px;">
                重点:战略、头部、战新客户；难点:省公司无法自行解决，需集团特派员协调。
            </div>
            <van-field v-if="fromdata.isDifficultProject === '是'" :readonly="!isLegionProjectEditable" autosize
                type="textarea" rows="1" name="reason" v-model="fromdata.reason" label="重点难点项目说明:" label-width="9em" />

        </van-cell-group>
        <!-- 移动云解决方案 -->
        <van-field readonly required name="isCloudSolution"
                     :value="fromdata.isCloudSolution=='1' ? '是' : '否'" label="是否包含移动云解决方案:" label-width="11.5em"/>
        <van-field v-if="fromdata.isCloudSolution === '1'" readonly name="industrySceneScheme" :value="fromdata.industrySceneScheme" label="涉及重点行业场景解决方案:"
                     label-width="12.5em"/>
        <van-field v-if="hasMoreFile" label="中标通知书下达时间:" name="issueDate" :value="mFromdata.issueDate" label-width="10em" readonly />

        <!-- 附件区 -->
        <div>

            <!-- 附件 投标才有的附近 -->
            <div v-if="hasMoreFile">

                <van-field v-if="hasMoreFile" label-width="10em" readonly label="招标文件:" class="lyy-width"
                    input-align="left" required placeholder="">
                </van-field>
                <div v-for="(fileitem, index) in fromdata.clientFile" :key="'clientFile'+index"
                    style="margin-left:20px; margin-top: 5px">
                    <div v-if="hasMoreFile" readonly class="font14 fileLink" style="color:#0F85CF">
                        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName
                            }}</a>
                    </div>
                </div>

                <van-field v-if="hasMoreFile" label-width="10em" readonly label="应标文件:" class="lyy-width"
                    input-align="left" required placeholder="">
                </van-field>
                <div v-for="(fileitem, index) in fromdata.companyFile" :key="'companyFile'+index"
                    style="margin-left:20px; margin-top: 5px">
                    <div v-if="hasMoreFile" readonly class="font14 fileLink" style="color:#0F85CF">
                        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName
                            }}</a>
                    </div>
                </div>


                <van-field v-if="hasMoreFile" label-width="10em" readonly label="中标通知书:" class="lyy-width"
                    input-align="left" required placeholder="">
                </van-field>
                <div v-for="(fileitem, index) in fromdata.winBidFile" :key="'winBidFile'+index"
                    style="margin-left:20px; margin-top: 5px">
                    <div v-if="hasMoreFile" readonly class="font14 fileLink" style="color:#0F85CF">
                        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName
                            }}</a>
                    </div>
                </div>

                <van-field v-if="hasMoreFile" label-width="10em" readonly label="采购需求文件:" class="lyy-width"
                    input-align="left" required placeholder="">
                </van-field>
                <div v-for="(fileitem, index) in fromdata.purchaseFile" :key="'purchaseFile'+index"
                    style="margin-left:20px; margin-top: 5px">
                    <div v-if="hasMoreFile" readonly class="font14 fileLink" style="color:#0F85CF">
                        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName
                            }}</a>
                    </div>
                </div>

            </div>



            <van-field readonly required label-width="6em" label="预立项文件:"
                :rules="[{ required: fromdata.projectDecisionDocument === undefined || fromdata.projectDecisionDocument === null || fromdata.projectDecisionDocument.length === 0, message: '请上传预立项文件' }]">
                <template #button v-if="projectDecisionDocumentEditable">
                    <van-uploader name="projectDecisionDocument" :after-read="didFinishPickingFiles">
                        <van-button native-type="button" size="small" type="primary">上传附件</van-button>
                    </van-uploader>
                </template>
            </van-field>
            <div v-for="(fileitem, index) in fromdata.projectDecisionDocument" :key="'projectDecisionDocument' +index"
                style="margin-left:20px; margin-top: 5px;">
                <div readonly class="font14 fileLink" style="color:#0F85CF">
                    <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName
                        }}</a>
                </div>

                <van-icon v-if="projectDecisionDocumentEditable" name="close" color="#ea0023" size="20px"
                    @click="deleteFile('projectDecisionDocument', index)"></van-icon>
            </div>



            <van-field label-width="10em" readonly label="技术方案:" class="lyy-width" input-align="left" required
                placeholder="">
            </van-field>
            <div v-for="(fileitem, index) in fromdata.technicalPlanFile" :key="'technicalPlanFile'+index"
                style="margin-left:20px; margin-top: 5px; ">
                <div readonly class="font14 fileLink" style="color:#0F85CF">
                    <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName
                        }}</a>
                </div>
            </div>


            <van-field label-width="10em" readonly label="前向合同扫描件:" class="lyy-width" input-align="left" required
                placeholder="">
            </van-field>
            <div v-for="(fileitem, index) in fromdata.contractFile" :key="'contractFile'+index"
                style="margin-left:20px; margin-top: 5px;">
                <div readonly class="font14 fileLink" style="color:#0F85CF">
                    <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName
                        }}</a>
                </div>
            </div>


            <van-field label-width="10em" readonly label="后向合同扫描件:" class="lyy-width" input-align="left" required
                placeholder="">
                <template #button v-if="newContractFileEditable">
                    <van-uploader name="newContractFile" :after-read="didFinishPickingFiles">
                        <van-button native-type="button" size="small" type="primary">AI+</van-button>
                    </van-uploader>
                </template>
            </van-field>
            <div v-for="(fileitem, index) in fromdata.newContractFile" :key="'newContractFile'+index"
                style="margin-left:20px; margin-top: 5px">
                <div readonly class="font14 fileLink" style="color:#0F85CF">
                    <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName
                        }}</a>
                </div>

                <van-icon v-if="newContractFileEditable" name="close" color="#ea0023" size="20px"
                    @click="deleteFile('newContractFile', index)"></van-icon>
            </div>
            <div v-if="aiDataResult&&aiDataResult.resultData&&!sysFiles&&sysFiles.length<1">
              <ai-el-table :aiDataResult="aiDataResult"></ai-el-table>
            </div>
            <div v-else-if="newContractFileEditable&&sysFiles&&sysFiles.length>0">
              <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
                <div class="blue_item" />
                <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">AI解析结果</span>
              </div>
              <el-table  :data="sysFiles" border style="width: 100%">
                <el-table-column prop="fileName" width="100px" label="文档名称" />
                <el-table-column prop="creator" label="上传人" />
                <el-table-column prop="createdTime" label="上传时间" />
                <el-table-column prop="state" label="AI解析状态" />
              </el-table>
              <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
                <div class="blue_item" />
                <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">AI解析详情</span>
              </div>
              <el-table  :data="analysisData" border style="width: 100%">
                <el-table-column type="index" width="40px" label="序号" />
                <el-table-column prop="fieldName" label="关键字段名称" />
                <el-table-column prop="dictValue" label="DICT系统数据" />
                <el-table-column label="AI解析结果" >
                  <template v-slot:default="scope">
                    <div v-if="Array.isArray(scope.row.aiOldValue) && scope.row.aiOldValue.length>0&&isBase64(scope.row.aiOldValue[0])" >
                      <div v-for="(item,index) in scope.row.aiOldValue" :key="index">
                        <img :src="'data:image/jpg;base64,'+item" style='width:50px;margin-left:5px;cursor:pointer;'>
                      </div>
                    </div>
                    <div v-else class="w100 f-1">
                      <div>{{scope.row.aiOldValue}}</div>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="equalResult" label="一致性对比结果" >
                  <template v-slot:default="scope">
                    <div class="w100 f-1">
                      <div v-if="scope.row.equalResult=='不一致'" style="color: red">{{scope.row.equalResult}}</div>
                      <div v-else-if="scope.row.equalResult=='一致'" style="color: green">{{scope.row.equalResult}}</div>
                      <div v-else>{{scope.row.equalResult}}</div>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="editValue" label="人工修正AI解析结果" width="200" align="center">
                  <template slot-scope="scope">
                    <van-field
                        v-model="scope.row.editValue"
                        rows="1"
                        autosize
                        label=""
                        type="textarea"
                        placeholder="请输入修正内容"
                        @blur="editValueChange(scope.$index,scope.row.editValue)"
                    />
                  </template>
                </el-table-column>
              </el-table>
            </div>
        </div>


        <!-- 当前办理人 -->
        <section-header v-if="showHistoryMoudle" :sectionTitle="'当前办理人:'" />
        <div v-if="showHistoryMoudle" class="font13 ptandpb10 pl16">
            <div>
                <span class="titletext font13">{{
                    historydata.MANAGER
                    }}</span>
            </div>
            <div class="mt5">
                <span class="graytext font12">{{ historydata.DEPARTMENT }}</span>
            </div>
        </div>


        <!-- 审批意见 -->
        <section-header v-if="showOpinionMoudle" id="opinion" :sectionTitle="'审批意见:'" />
        <opinion-item v-if="showOpinionMoudle" :approveList="approveList" />

    </div>
</template>

<script>

import { openFileUrl } from '@/store/openFile'
import OpinionItem from '../sztdzj/sztdzjDetail/opinion-item.vue';
import SectionHeader from '../sztdzj/sztdzjDetail/section-header.vue';
import {Dialog, Notify, Toast} from 'vant';
import { mapGetters } from 'vuex';
import {uploadFileCommon, getDictList, fileParsingCurrencyHttp, getPublicCountyCode, req} from "@/api/dictapi";
import { Choose_HYJY_DICT_KEY, Choose_HYJY_KEY } from '../../assets/js/dict_process_helper';
import PageSelectXmList from '/src/components/page_select_xm_list/index.vue';
import aiElTable from "@/components/aiElTable/index.vue";
import util from "@/assets/js/public";
import aiUtils from "@/assets/js/aiUtils";


export default {
    data() {
        return {

            isArrangePayTimeColumns: [{ 'name': '是', 'value': '是' }, 
            { 'name': '否', 'value': '否' }],
            isArrangePayTimeShowPopup: false,

            isLegionProjectShowPopupView: false,
            isDifficultProjectShowPopupView: false,
            industryLegionShowPopupView: false,
            industryLegionPopupColumns: [],
            industryLegionDict: { '安全+军团': '启明星辰', 
            '视觉+军团': '物联网公司', 
            '智慧公安军团': '集成公司', 
            '应急管理军团': '集成公司', 
            '新型工业化军团': '上研院', 
            '智慧校园军团': '成研院', 
            'AI+军团': '云能力中心', 
            '车联网军团': '上研院' }, // 各军团和专业公司对应关系

            industryLegionUnitsShowPopupView: false,
            industryLegionUnitsPopupColumns: [],

            productLegionShowPopupView: false,
            productLegionPopupColumns: [],

            productLegionUnitsShowPopupView: false,
            productLegionUnitsPopupColumns: [],

            jtxm_lxr_showPopupView: false,
          sysFiles: [],
          analysisData:  [],
          idKey: '',
          showCountyPopup:false,
          showCountyPickeColumns:[],
          publicCountyCodeValue:'',
          publicCountyCode:'',
        }
    },
    props: {params: {
        type: Object,
        default: () => { }
      },fromdata: {
        type: Object,
        default: () => { }
      },mFromdata: {
        type: Object,
        default: () => { }
      },decisionMaking: {
        type: Object,
        default: () => { }
      },historydata: {
        type: Object,
        default: () => { }
      },approveList: {
        type: Array,
        default: () => []
      },aiDataResult: {
        type: Object,
        default: () => { }
      },isSJ: {
        type: Boolean,
        default: false
      }},
  watch: {
    sysFiles: {
      handler() {
        this.$emit('freshSysFiles', this.sysFiles)
      },
      deep: true,  // 可以深度检测到 obj 对象的属性值的变化
      immediate: true //刷新加载  立马触发一次handler
    },
    analysisData: {
      handler() {
        this.$emit('freshAnalysisData', this.analysisData)
      },
      deep: true,  // 可以深度检测到 obj 对象的属性值的变化
      immediate: true //刷新加载  立马触发一次handler
    },
    idKey: {
      handler() {
        this.$emit('freshIdKey', this.idKey)
      },
      deep: true,  // 可以深度检测到 obj 对象的属性值的变化
      immediate: true //刷新加载  立马触发一次handler
    },
    publicCountyCode: {
      handler() {
        this.$emit('freshCountyCode', this.publicCountyCode)
      },
      deep: true,  // 可以深度检测到 obj 对象的属性值的变化
      immediate: true //刷新加载  立马触发一次handler
    },
  },
    computed: {

        ...mapGetters(["user"]),

        /// 意见
        showOpinionMoudle() {
            return this.params.isDrawup != '1';
        },

        // 当前办理人
        showHistoryMoudle() {
            return this.params.todoType == "2" && (this.historydata && Object.keys(this.historydata).length > 0 && this.historydata.MANAGER) && this.params.isDrawup != '1';
        },

        // 售中售后阶段项目定级是否展示
        showGradeFinal() {

            return this.params.location == 'dict.TradeEnginerToGiveManager'
                || this.params.location == 'dict.ToStart'
                || this.params.location == 'dict.FirstAdminToSecondAdminME'
                || this.params.location == 'dict.managerGradeToCustomer'
                || this.params.location == 'dict.managerGradeToLeader'
                || this.params.location == 'dict.SecondAdminToThirdManager'
                || this.params.location == 'dict.SecondAdminToThirdManager'
                || this.params.location == 'dict.FirstAdminToSecondAdminMF'
                || this.params.location == 'dict.managerGradeToCustomer'
                || this.params.location == 'dict.managerGradeToLeader';
        },

        // 投标 多出来四个附件
        hasMoreFile() {

            return this.fromdata.competitiveMode == '投标';
        },

        // 军团项目 可否编辑
        isLegionProjectEditable() {
            return this.params.location === 'dict.start' || this.params.isDrawup == '1';
        },
        
        isArrangePayTimeEditable() {
            return this.params.location === 'dict.start' || this.params.isDrawup == '1';
        },

        projectDecisionDocumentEditable() {
            return (this.params.location === 'dict.start' || this.params.isDrawup == '1') && (!this.fromdata.projectDecisionDocument || this.fromdata.projectDecisionDocument.length == 0);
        },

        newContractFileEditable() {
            return (this.params.location === 'dict.start' || this.params.isDrawup == '1') && (!this.fromdata.newContractFile || this.fromdata.newContractFile.length == 0);
        },
        chooseMeetingEditable() {
            return ((this.params.location === 'dict.start' && this.params.todoType == 1) || this.params.isDrawup == '1') && this.decisionMaking.decisionLevel;
        }

    },

    //生命周期--挂载完成
    components: {
      aiElTable,

        OpinionItem,
        SectionHeader,
        PageSelectXmList
    },

    activated() {

      this.hyjy_refreshFromData();
      if (localStorage.getItem('xmdjType') != '{}' && localStorage.getItem('xmdjType')) {
        this.fromdata.onProjectGradeFinal = JSON.parse(localStorage.getItem('xmdjType'))
      }
    },

    methods: {
      showCountyPicke(){
        if(this.fromdata.city){
          this.getPublicCountyCode(true)
        }else {
          Notify('地市信息不完整')
        }
      },
      showCountyPickeOnConfirm(value){
        this.showCountyPopup=false
        this.fromdata.publicCountyCodeValue=value.name
        this.fromdata.publicCountyCode=value.value
        this.publicCountyCodeValue=value.name
        this.publicCountyCode=value.value
      },
      getPublicCountyCode(isPick) {
        getPublicCountyCode({userName:this.user.userName,city:this.fromdata.city})
            .then((result)=>{
              Toast.clear();
              if(!result.data){
                Notify(result.message);
                return;
              }
              if(result.data.data){
                this.showCountyPickeColumns=result.data.data
                this.showCountyPopup=true
              }
            })
      },
      editValueChange(index,value){
        if (this.analysisData[JSON.stringify(index)].dictValue==value){
          this.analysisData[JSON.stringify(index)].equalResult='一致'
        }
        this.analysisData=JSON.parse(JSON.stringify(this.analysisData))
      },
        getITList(){
          this.$router.push(
            {
              name: 'xmdj',
              query: {
                fromdata: this.fromdata,
                mFromdata: this.mFromdata
              }
            })
        },
        tomsg() {
            document.getElementById('opinion').scrollIntoView({ behavior: 'smooth' })
        },

        openFileUrlfun(value) {
            this.$router.push(
                {
                    name: 'fileview',
                    query: {
                        openFileUrl: openFileUrl(value)
                    }
                }
            );
        },

        // 刷新会议纪要数据
        hyjy_refreshFromData() {

            if (localStorage.getItem(Choose_HYJY_KEY) != '{}' &&
                localStorage.getItem(Choose_HYJY_KEY)) {

                let hyjyInfo = JSON.parse(localStorage.getItem(Choose_HYJY_KEY));
                localStorage.setItem(Choose_HYJY_KEY, '{}')
                console.log(hyjyInfo);

                if (!this.isSJ) {
                    this.decisionMaking.meetingTheme = hyjyInfo.title;
                    this.decisionMaking.meetingNumber = hyjyInfo.zihao;
                }
                else {
                    this.decisionMaking.meetingThemeCompany= hyjyInfo.title;
                    this.decisionMaking.meetingNumberCompany = hyjyInfo.zihao;
                }
            }

            if (localStorage.getItem(Choose_HYJY_DICT_KEY) != '{}' &&
                localStorage.getItem(Choose_HYJY_DICT_KEY)) {

                let hyjyInfo = JSON.parse(localStorage.getItem(Choose_HYJY_DICT_KEY));
                localStorage.setItem(Choose_HYJY_DICT_KEY, '{}')

                console.log(hyjyInfo);
                if (!this.isSJ) {
                    this.decisionMaking.meetingTheme = hyjyInfo.meetingTheme;
                    this.decisionMaking.meetingNumber = hyjyInfo.meetingNumber;
                }
                else {
                    this.decisionMaking.meetingThemeCompany = hyjyInfo.meetingTheme;
                    this.decisionMaking.meetingNumberCompany = hyjyInfo.meetingNumber;
                }
            }
        },

        chooseMeetingNumber() {

            this.$router.push({
                name: "xmjj_select_hyjy_tab",
            });
        },

        // 查看联系人信息，点击无回调
        handleSelectItem(value) {

            this.jtxm_lxr_showPopupView = false;

        },



        // TODO: 网络请求
        requestAlertInfo(value, callback) {

            Toast.loading({ message: "加载中", forbidClick: false });
            getDictList(value, { userName: this.user.userName }).then((result) => {
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {
                    callback(result.data.data);
                }
            });
        },


        // TODO:弹窗显示
        industryLegionClick() {

            if (this.isLegionProjectEditable) {

                if (this.industryLegionPopupColumns.length == 0) {

                    this.requestAlertInfo('industryLegion', (data) => {

                        this.industryLegionPopupColumns = data;
                        this.industryLegionShowPopupView = true;
                    });
                }
                else
                {
                    this.industryLegionShowPopupView = true;
                }
            }
        },

        productLegionClick() {

            if (this.isLegionProjectEditable) {
                if (this.productLegionPopupColumns.length == 0) {

                    this.requestAlertInfo('productLegion', (data) => {

                        this.productLegionPopupColumns = data;
                        this.productLegionShowPopupView = true;
                    });
                }
                else
                {
                    this.productLegionShowPopupView = true;
                }
            }

        },

        industryLegionUnitsClick() {

            if (this.isLegionProjectEditable) {
                if (this.industryLegionUnitsPopupColumns.length == 0) {

                    this.requestAlertInfo('legionUnits', (data) => {

                        this.industryLegionUnitsPopupColumns = data;
                        this.industryLegionUnitsShowPopupView = true;
                    });
                }
                else
                {
                    this.industryLegionUnitsShowPopupView = true;
                }

            }

        },

        productLegionUnitsClick() {

            if (this.isLegionProjectEditable) {

                if (this.productLegionUnitsPopupColumns.length == 0) {

                    this.requestAlertInfo('legionUnits', (data) => {

                        this.productLegionUnitsPopupColumns = data;
                        this.productLegionUnitsShowPopupView = true;
                    });
                }
                else
                {
                    this.productLegionUnitsShowPopupView = true;
                }
            }
            
        },


        // TODO: 弹窗回调事件
        isLegionProjectClickConfirm(value) {

            this.isLegionProjectShowPopupView = false;
            this.fromdata.isLegionProject = value.name;
        },

        isDifficultProjectClickConfirm(value) {

            this.isDifficultProjectShowPopupView = false;
            this.fromdata.isDifficultProject = value.name;
        },

        industryLegionClickConfirm(value) {

            this.industryLegionShowPopupView = false;
            this.fromdata.industryLegion = value.name;

            let val = this.industryLegionDict[value.name];
            this.fromdata.industryLegionUnits = val;
        },

        industryLegionUnitsClickConfirm(value) {

            this.industryLegionUnitsShowPopupView = false;
            this.fromdata.industryLegionUnits = value.name;
        },

        productLegionClickConfirm(value) {

            this.productLegionShowPopupView = false;
            this.fromdata.productLegion = value.name;

            let val = this.industryLegionDict[value.name];
            this.fromdata.productLegionUnits = val;
        },

        productLegionUnitsClickConfirm(value) {

            this.productLegionUnitsShowPopupView = false;
            this.fromdata.productLegionUnits = value.name;
        },

        isArrangePayTimeConfirm(value) {

            this.isArrangePayTimeShowPopup = false;
            this.fromdata.isArrangePayTime = value.name;
        },
        /// 本地文件选中后的回调
        didFinishPickingFiles(file, detail) {
            console.log('照片上传', detail);
            Toast.loading({
                message: '上传中...',
                forbidClick: true,
            });
            let fileData = new FormData();
            fileData.append("pmInsType", this.pmInsType);
            fileData.append("pmInsTypePart", "1");
            fileData.append("files", file.file);

            let params = new Map();
            params.pmInsType = this.pmInsType;
            params.pmInsTypePart = '1';
            params.userName = this.user.userName;
            uploadFileCommon(fileData, params).then((res) => {
                Toast.clear();
                if (!res.data) {
                    Notify(res.message);
                    return;
                }
                if (res.data.data) {
                    this.showUploadFiles(res.data.data, detail.name);
                }
            });
        },
        // 上传附近后的 回显
        showUploadFiles(fileData, key) {
            if (this.fromdata[key] === null ||
                this.fromdata[key] === undefined) {
                this.fromdata[key] = [];
            }
            console.log('照片回显', key, this.fromdata[key]);
            if(key=='newContractFile'){
              this.fromdata.newContractFile=fileData.sysFiles;
            }else {
              this.fromdata[key].push(fileData.sysFiles[0]);
            }
            this.$forceUpdate(); // 强制刷新界面
            if(key=='newContractFile'){
              Dialog.confirm({ title: "提示", message: "是否使用AI大模型能力对文件进行解析？" })
                .then(() => {
                  let projectIdV = "";
                  if(this.fromdata.projectID){
                    projectIdV=this.fromdata.projectID
                  }else if (this.fromdata.projectEstablishNumber){
                    projectIdV=this.fromdata.projectEstablishNumber
                  }
                  let businessId = "";
                  if(this.fromdata.businessId){
                    businessId=this.fromdata.businessId
                  }
                  Toast.loading({
                    message: '解析中...',
                    forbidClick: false,
                  });
                  fileParsingCurrencyHttp(Object.assign(this.params, { userName: this.user.userName,businessId:businessId ,projectId: projectIdV, fileId: fileData.sysFiles[0].id ,analysisCode: "HeTongJieXi"})).then((result) => {
                    Toast.clear();
                    if (!result.data) {
                      Notify(result.message);
                      return;
                    }
                    if (result.data.data) {
                      this.sysFiles=[]
                      this.sysFiles=fileData.sysFiles
                      this.analysisData=[]
                      if (result.data.data) {
                        this.idKey = result.data.data.id;
                        for(var i in result.data.data){
                          if(i != "id"){
                            if  (Array.isArray(result.data.data[i])&&result.data.data[i].length<1){
                              this.analysisData.push({
                                fieldName: i,
                                aiOldValue: '[]',//AI解析原数据
                                aiValue: '[]'//将AI解析的数据进行格式化
                              });
                            }else {
                              this.analysisData.push({
                                fieldName: i,
                                aiOldValue: result.data.data[i],//AI解析原数据
                                aiValue: aiUtils.valueFormatter(result.data.data[i])//将AI解析的数据进行格式化
                              });
                            }
                          }
                        }
                        this.sysFiles[0].state = "执行成功";
                      }else {
                        this.sysFiles[0].state = "执行失败";
                      }
                      for(var i in this.analysisData){
                        this.analysisData[i].dictField = "aiMark"+(parseInt(i)+1);//字段标识
                        this.analysisData[i].dictValue = this.setValueData(this.analysisData[i]);
                        this.analysisData[i].editValue = "";
                      }
                      for(var i in this.analysisData){
                        var dictValue = this.analysisData[i].dictValue;
                        console.log('this.analysisData[i].dictValue'+this.analysisData[i].dictValue)
                        // 时间特殊处理
                        if(this.analysisData[i].dictValue.indexOf("-")>-1 && this.analysisData[i].dictValue.indexOf(":")>-1){
                          dictValue = this.analysisData[i].dictValue.split(" ")[1];
                        }
                        // 比率
                        if(dictValue.indexOf("%") > -1){
                          var num_regxa = /^[\-\+]?(([0-9]+)([\.,]([0-9]+))?|([\.,]([0-9]+))?)$/;//数字
                          var dictNumStr = dictValue.replace("%","");
                          if(num_regxa.test(dictNumStr)){
                            dictValue = dictNumStr;
                          }
                        }
                        var aiValue = this.analysisData[i].editValue?this.analysisData[i].editValue:(this.analysisData[i].aiValue?this.analysisData[i].aiValue:"");

                        // 判断DICT系统数据和集团数据是否一致
                        if(this.analysisData[i].dictValue=="未提及" || this.analysisData[i].aiValue=="未提及"){
                          this.analysisData[i].equalResult = "不涉及";
                        }else{
                          this.analysisData[i].equalResult = dictValue==aiValue?"一致":"不一致";
                        }
                        this.analysisData[i].editValue = this.analysisData[i].editValue || "";
                      }
                    }
                  });
                })
                .catch(() => { });
            }
        },
        // 判断是否是base64编码
        isBase64(str){
          var regex = /^(?:[A-Za-z0-9+/]{4})*?(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/;
          return regex.test(str);
        },
        getFormValue(key){
          console.log("合同数据是"+JSON.stringify(this.mFromdata.contractInfo))
          for (let i in this.mFromdata.contractInfo){
            if (this.mFromdata.contractInfo[i].contractIncExpType == "支出类") {
              return String(this.mFromdata.contractInfo[i][key])
            }else if (this.mFromdata.contractInfo[i].contractIncExpType == "有收有支类"||this.mFromdata.contractInfo[i].contractIncExpType == "有收有支") {
              return String(this.mFromdata.contractInfo[i][key])
            }
          }
        },
        setValueData(data){
          var valueInfos=''
          console.log("需要对应的名字是"+data.fieldName)
          if(data.fieldName == '项目名称'){
            valueInfos= this.fromdata.projectName
          }else if(data.fieldName == '乙方盖章'){
            valueInfos= '未提及'
          }else if(data.fieldName == '甲方盖章'){
            valueInfos= '未提及'
          }else if(data.fieldName == '签订日期'){
            valueInfos=  this.getFormValue('contractSignedDate')
          }else if(data.fieldName == '合同乙方名称'){
            valueInfos=  this.getFormValue('contractPartyB')
          }else if(data.fieldName == '合同甲方名称'){
            valueInfos=  this.getFormValue('contractPartyA')
          }else if(data.fieldName == '合同总金额（小写）含税'){
            valueInfos=  this.getFormValue('amountTax')
          }else if(data.fieldName == '项目年限'){
            valueInfos=  this.getFormValue('projectDuration')
          }else if(data.fieldName == '合同总金额（大写）不含税'){
            valueInfos=  this.getFormValue('contractAmountUppercase')
          }else if(data.fieldName == '合同总金额（小写）不含税'){
            valueInfos=  this.getFormValue('contractAmountLowercase')
          }else if(data.fieldName == '乙方签字'){
            valueInfos=  this.getFormValue('personPartyB')
          }else if(data.fieldName == '甲方签字'){
            valueInfos=  this.getFormValue('personPartyA')
          }else if(data.fieldName == '合同总金额（大写）含税'){
            valueInfos=  this.getFormValue('contractTaxAmountUppercase')
          }else if(data.fieldName == '合同有效期'){
            valueInfos=  this.getFormValue('contractValidity')
          }
          if (!valueInfos){
            valueInfos='未提及'
          }
          return valueInfos
        },
        deleteFile(key, index) {
            Dialog.confirm({ title: "提示", message: "是否删除此附件？" })
                .then(() => {
                    this.fromdata[key].splice(index, 1);
                    this.$forceUpdate(); // 强制刷新界面
                })
                .catch(() => { });
        },
    }
}
</script>

<style lang="scss" scoped></style>